package etnorservice.etnor_service.utils;

import etnorservice.etnor_service.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: cc
 * @Date: 2024/08/23/15:19
 **/
@Service
public class RoleSecurityUtils {
    @Autowired
    UserService userService;
    public boolean isAdmin(String token){

        String account=
                new JwtTokenUtil().
                        getAccountFromToken(extractTokenFromHeader(token));
        System.out.println("账号信息"+account);
        int role=userService.findRoleByAccount(Integer.parseInt(account)).getRole();
        if(role==1){
            return false;
        }
            return true;

    }
    private String extractTokenFromHeader(String header) {
        if (header == null || !header.startsWith("Bearer ")) {
            return null;
        }
        return header.substring(7).trim(); // 去除 "Bearer ".length() 后面的空格
    }
}
